<!--
 * @Descripttion: 
 * @version: 
 * @Author: zhaoxiaodong
 * @Date: 2020-09-01 16:46:01
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2020-11-19 14:09:48
-->
<template>
  <div class="patchPack-list">
    <cloudBreadcrumb :routes="routes"></cloudBreadcrumb>
    <cloudSearch
      :maxLength="15"
      class="keyword-search"
      placeholder="请输入关键字搜索"
      :width="230"
      v-model="keyword"
      @search="onSearch"
    ></cloudSearch>

    <div class="tool-list-flex list">
      <div class="tool-list-col" v-for="item in list" :key="item.id">
        <div class="item">
          <div class="item-title">
            <span class="item-title-left">
              <app-icon
                iconName="vcloud-yingyongjieru"
                className="title__icon"
              ></app-icon>
              <span :title="item.packageName"> {{ item.packageName }}</span>
            </span>
            <span
              class="item-title-right"
              @click="getDownloadFixPackUrl(item.obsFileId, item.packageName)"
            >
              <app-icon
                iconName="vcloud-xiazai"
                className="xiazai__icon"
              ></app-icon>
            </span>
          </div>
          <div class="item-content">
            <div class="item-content-block">
              <span class="block-left">发布时间：</span>
              <span class="block-right">{{
                item.serverCreateTime | formatTime("YYYY-MM-DD")
              }}</span>
            </div>
            <div class="item-content-middle">
              <span class="middle-left">适配版本：</span>
              <span class="middle-right" :title="item.version">{{
                item.version
              }}</span>
            </div>
            <div
              class="item-content-bottom"
              :title="item.packageDesc"
              v-html="item.packageDesc"
            ></div>
          </div>
        </div>
      </div>
    </div>
    <CloudPagination
      v-show="!loading"
      @onShowSizeChange="num => (pageSize = num)"
      @change="num => (currentPage = num)"
      :current="currentPage"
      :pageSizeOptions="['40', '60', '80', '100']"
      :pageSize="pageSize"
      :showSizeChanger="true"
      :showQuickJumper="true"
      :showTotal="total => `共 ${total} 条`"
      :total="total"
    ></CloudPagination>
  </div>
</template>

<script>
import {
  CloudBreadcrumb,
  CloudSearch,
  CloudPagination
} from 'cloud-components';
export default {
  name: 'patchPack',
  data() {
    return {
      keyword: '',
      loading: false,
      currentPage: 1,
      pageSize: 40,
      total: 0,
      list: [],
      routes: [
        {
          path: 'index',
          breadcrumbName: '工具箱'
        },
        {
          path: '/patchPack',
          breadcrumbName: '补丁包下载'
        }
      ]
    };
  },
  components: {
    cloudBreadcrumb: CloudBreadcrumb,
    cloudSearch: CloudSearch,
    CloudPagination
  },
  computed: {},

  created() {
    this.getData();
  },

  methods: {
    onSearch(value) {
      this.keyword = value;
      this.getData();
    },
    getData(page) {
      this.loading = true;
      this.list = [];
      if (page) {
        this.currentPage = page;
      } else {
        this.currentPage = 1;
      }
      this.api
        .pageFixPack({
          packageName: this.keyword,
          page: this.currentPage,
          size: this.pageSize
        })
        .then(res => {
          this.loading = false;
          this.list = res.data.data;
          this.total = Number(res.data.total);
        })
        .catch(e => {
          this.loading = false;
        });
    },
    getDownloadFixPackUrl(obsFileId, name) {
      this.api
        .getDownloadFixPackUrl(
          { params: { obsFileId: obsFileId } },
          { customRequest: true, method: 'get' }
        )
        .then(res => {
          this.loading = false;
          Object.assign(document.createElement('a'), {
            download: name,
            href: res.data
          }).click();
        })
        .catch(e => {});
    }
  },
  watch: {
    currentPage(v) {
      this.getData(v);
    },
    pageSize() {
      this.getData();
    }
  }
};
</script>

<style lang="scss">
.patchPack-list {
  margin: auto;
  max-width: 1260px;
  padding: 10px 0 30px 0;
  .keyword-search {
    margin: 16px 0;
  }
  .tool-list-flex {
    margin-left: -20px;
    margin-right: -20px;

    display: flex;
    flex-flow: row wrap;
    .tool-list-col {
      padding-left: 20px;
      padding-right: 20px;
      display: block;
      box-sizing: border-box;
      width: 33.33333333%;
      flex: 0 0 auto;
      float: left;
    }
  }
  .list {
    padding-bottom: 15px;
    margin-top: 10px;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    min-height: 250px;
  }
  .item {
    background: #ffffff;
    box-shadow: 0px 20px 20px 0px rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    &-title {
      height: 40px;
      background: #eff3f9;
      border-radius: 5px 5px 0px 0px;
      padding: 0 14px;
      line-height: 40px;
      display: flex;
      &-left {
        font-size: 16px;
        font-weight: 600;
        color: #000000;
        flex: 1;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        word-break: break-all;
        .title__icon {
          color: #4bb81e;
          // width: 14px;
          // height: 15px;
          font-size: 18px;
          margin-right: 5px;
        }
      }
      &-right {
        cursor: pointer;
        margin-left: 20px;
        .xiazai__icon {
          height: 17px;
          color: #336cfb;
          font-size: 18px;
        }
      }
    }

    &-content {
      padding: 20px;
      background-image: url("./images/xiazaiBG.png");
      background-repeat: no-repeat;
      background-position: 98% 65px;
      background-size: 68px 64px;
      &-block {
        margin-bottom: 8px;
        .block-left {
          font-size: 14px;
          font-weight: 400;
          color: #666666;
        }
        .block-right {
          font-size: 14px;
          font-weight: 500;
          color: #333333;
        }
      }
      &-middle {
        display: flex;
        .middle-left {
          font-size: 14px;
          font-weight: 400;
          color: #666666;
        }
        .middle-right {
          font-size: 14px;
          font-weight: 500;
          height: 42px;
          flex: 1;
          color: #333333;
          text-overflow: -o-ellipsis-lastline;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          line-clamp: 2;
          -webkit-box-orient: vertical;
          word-break: break-all;
        }
      }
      &-bottom {
        font-size: 12px;
        font-weight: 400;
        color: #666666;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        word-break: break-all;
        a {
          cursor: pointer;
        }
      }
    }
  }
  .cloud-pagination {
    padding: 10px 5px;
    text-align: right;
    width: 1260px;
    margin: 0 auto;
    position: fixed;
    bottom: 40px;
  }
  .cloud-pagination /deep/ * {
    box-sizing: border-box;
  }
}
</style>
